package day17;

import javax.naming.ldap.Rdn;
import java.util.Random;

public class Sensor{
    int sum=9;
    Random rd=new Random();
    public void temperature() throws InterruptedException {
        String name=Thread.currentThread().getName();
        for (int i=0;i<sum;i++){
            Thread.sleep(500);
            int n=rd.nextInt(21)+20;
            System.out.println(name+":"+n);
        }
    }

    public void humidity() throws InterruptedException {
        String name=Thread.currentThread().getName();
        for (int i=0;i<sum;i++) {
            Thread.sleep(400);
            int n = rd.nextInt(21) + 70;
            System.out.println(name + ":" + n);
        }
    }
    public void light() throws InterruptedException {
        String name=Thread.currentThread().getName();
        for (int i=0;i<sum;i++){
            Thread.sleep(300);
            int n=rd.nextInt(61)+20;
            System.out.println(name+":"+n);
        }
    }

    public static void main(String[] args) {
         Sensor ss=new Sensor();
         new Thread(()->{
             for (int i=0;i<9;i++){
                 try {
                     ss.temperature();
                 } catch (InterruptedException e) {
                     e.printStackTrace();
                 }
             }
         },"温度传感器").start();
        new Thread(()->{
            for (int i=0;i<9;i++){
                try {
                    ss.humidity();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"湿度传感器").start();
        new Thread(()->{
            for (int i=0;i<9;i++){

                try {
                    ss.light();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"光照传感器").start();
    }
}
